//
//  CZDefaultCenterView.m
//  小和微博
//
//  Created by 董晓合 on 15/2/22.
//  Copyright (c) 2015年 itcast. All rights reserved.
//

#import "CZDefaultCenterView.h"

@interface CZDefaultCenterView()
//图标头像
@property (weak, nonatomic) IBOutlet UIImageView *icon;
//描述文字
@property (weak, nonatomic) IBOutlet UILabel *descriptionLb;
//登陆按钮
@property (weak, nonatomic) IBOutlet UIButton *loginBtn;
//注册按钮
@property (weak, nonatomic) IBOutlet UIButton *registerBtn;
/**
 *  登陆
 */
- (IBAction)loginBtnOnClick:(id)sender;
/**
 *  注册
 */
- (IBAction)regisetBtnOnClick:(id)sender;

// 定时器
@property (nonatomic, strong) CADisplayLink *link;

@end

@implementation CZDefaultCenterView

+ (instancetype)defaultCenterView {

    return [[[NSBundle mainBundle] loadNibNamed:@"CZDefaultCenterView" owner:nil options:nil] lastObject];
}

- (void)setIconImageName:(NSString *)iconImageName {

    self.icon.image = [UIImage imageNamed:iconImageName];
}

- (void)setInfo:(NSString *)info {

    self.descriptionLb.text = info;
}
/**
 *  开始转动
 */
- (void)startRotate {

// 创建定时器
    [self.link addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes];
}
- (void)stopRotate {

//销毁定时器
    [self.link invalidate];
    self.link = nil;
}
- (void)update {

    self.turntableIv.transform = CGAffineTransformRotate(self.turntableIv.transform, M_PI / 100);
}

- (IBAction)loginBtnOnClick:(id)sender {
    
    if ([self.delegate respondsToSelector:@selector(defaultCenterView:didClickLogin:)]) {
        [self.delegate defaultCenterView:self didClickLogin:sender];
    }
}

- (IBAction)regisetBtnOnClick:(id)sender {
    
    if ([self.delegate respondsToSelector:@selector(defaultCenterView:didClickRegister:)]) {
        [self.delegate defaultCenterView:self didClickRegister:sender];
    }
}

#pragma mark - 懒加载
- (CADisplayLink *)link {

    if (!_link) {
        _link = [CADisplayLink displayLinkWithTarget:self selector:@selector(update)];
    }
    return _link;
}
@end
